/**
 * 
 */
package com.dy.agent.agent.api.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dy.agent.agent.api.dal.mapper.AgentAnchorStatisticsMapper;
import com.dy.agent.agent.api.model.dto.StatisticsQueryCondition;
import com.dy.agent.agent.api.model.entiry.AgentAnchorStatistics;
import com.dy.agent.agent.api.service.AgentAnchorStatisticsService;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * @author macbook
 *
 */
@Service("agentAnchorStatisticsService")
public class AgentAnchorStatisticsServiceImpl implements AgentAnchorStatisticsService {

	@Resource
	private AgentAnchorStatisticsMapper agentAnchorStatisticsMapper;

	@Override
	public List<AgentAnchorStatistics> queryListByCondition(StatisticsQueryCondition queryCondition) {
		Example example = new Example(AgentAnchorStatistics.class);

		Criteria criteria = example.createCriteria();
		if (queryCondition.getGid() != null) {
			criteria.andEqualTo("gid", queryCondition.getGid());
		}
		if (queryCondition.getUid() != null) {
			criteria.andEqualTo("uid", queryCondition.getUid());
		}
		if (queryCondition.getStartDt() != null) {
			if (queryCondition.isCompaDtEqual()) {
				criteria.andGreaterThanOrEqualTo("dt", queryCondition.getStartDt());
			} else {
				criteria.andGreaterThan("dt", queryCondition.getStartDt());
			}

		}
		if (queryCondition.getEndDt() != null) {
			if (queryCondition.isCompaDtEqual()) {
				criteria.andLessThanOrEqualTo("dt", queryCondition.getEndDt());
			} else {
				criteria.andLessThan("dt", queryCondition.getEndDt());
			}
		}
		return agentAnchorStatisticsMapper.selectByExample(example);
	}

	@Override
	public List<AgentAnchorStatistics> querySum(StatisticsQueryCondition condition) {
		return agentAnchorStatisticsMapper.querySum(condition);
	}

}
